package com.hanhanxiaochong.zhongxiangchuanmei.presenter;

import com.hanhanxiaochong.zhongxiangchuanmei.bean.NewAddressBean;
import com.hanhanxiaochong.zhongxiangchuanmei.config.HttpPostService;
import com.hanhanxiaochong.zhongxiangchuanmei.presenter.base.BasePresenter;
import com.hanhanxiaochong.zhongxiangchuanmei.view.iview.INewAddressView;
import com.trello.rxlifecycle.components.support.RxAppCompatActivity;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.Api.BaseApi;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.Api.BaseObserver;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.Api.ResponseBase;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.http.RetrofitSource;

import java.util.HashMap;
import java.util.Map;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by RockPhoenix on 2018/5/27.
 */

public class NewAddressPresenter extends BasePresenter<INewAddressView> {

    public NewAddressPresenter(INewAddressView iView) {
        super(iView);
    }

    @Override
    public void startPost(RxAppCompatActivity rxAppCompatActivity, BaseApi baseApi) {

    }

    @Override
    public void startPost(RxAppCompatActivity rxAppCompatActivity, BaseApi baseApi, int state) {

    }

    public void addNewAddress(String token, String shop_name, String phone,
                              String province, String city, String area,
                              String address, String defaults) {
        Map<String, String> map = new HashMap<>();
        map.put("token", token);
        map.put("shop_name", shop_name);
        map.put("phone", phone);
        map.put("province", province);
        map.put("city", city);
        map.put("area", area);
        map.put("address", address);
        map.put("defaults", defaults);
        addSubscription(RetrofitSource.createApi(HttpPostService.class)
                .in_address(map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<ResponseBase<NewAddressBean>>(iView) {
                    @Override
                    public void onSuccess(ResponseBase<NewAddressBean> response) {
                        iView.addNewAddressSuccess();
                    }
                }));
    }

    public void editAddress(String token, String id, String shop_name, String phone,
                            String province, String city, String area,
                            String address, String defaults) {
        Map<String, String> map = new HashMap<>();
        map.put("token", token);
        map.put("id", id);
        map.put("shop_name", shop_name);
        map.put("phone", phone);
        map.put("province", province);
        map.put("city", city);
        map.put("area", area);
        map.put("address", address);
        map.put("defaults", defaults);
        addSubscription(RetrofitSource.createApi(HttpPostService.class)
                .up_ress(map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<ResponseBase<NewAddressBean>>(iView) {
                    @Override
                    public void onSuccess(ResponseBase<NewAddressBean> response) {
                        iView.editAddressSuccess();
                    }
                }));
    }
}
